import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
/**
 * import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'
 **/

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: {
        title: 'Dashboard',
        icon: 'dashboard',
        affix: true
      }
    }]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [{
    path: '/instructionalMatters',
    component: Layout,
    alwaysShow: true,
    name: 'instructionalMatters',
    meta: {
      title: '教务',
      icon: 'education'
    },
    children: [{
        path: '/instructionalMatters/class-course',
        name: 'class-course',
        meta: {
          title: '班级课程'
        },
        component: () => import('@/views/education-instructionalMatters/class-course/index'),
        children: [{
            path: '/instructionalMatters/class-course/class-course-query',
            name: 'class-course-query',
            meta: {
              title: '班级课程'
            },
            component: () => import('@/views/education-instructionalMatters/class-course/class-course')
          },
          {
            path: '/instructionalMatters/class-course-add',
            name: 'class-course-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/class-course/add')
          }
        ]
      },
      {
        path: '/instructionalMatters/teaching-intention',
        name: 'teaching-intention',
        meta: {
          title: '授课意向'
        },
        component: () => import('@/views/education-instructionalMatters/teaching-intention/index'),
        children: [{
            path: '/instructionalMatters/teaching-intention/teaching-intention-query',
            name: 'teaching-intention-query',
            meta: {
              title: '授课意向'
            },
            component: () => import('@/views/education-instructionalMatters/teaching-intention/teachingIntention')
          },
          {
            path: '/instructionalMatters/teaching-intention/teaching-intention-add',
            name: 'teaching-intention-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/teaching-intention/add')
          },
        ]
      },
      {
        path: '/instructionalMatters/teaching-tasks',
        name: 'teaching-tasks',
        meta: {
          title: '教学任务'
        },
        component: () => import('@/views/education-instructionalMatters/teaching-tasks/index'),
        children: [{
            path: '/instructionalMatters/teaching-tasks/teaching-tasks-query',
            name: 'teaching-tasks-query',
            meta: {
              title: '教学任务'
            },
            component: () => import('@/views/education-instructionalMatters/teaching-tasks/teachingTasks')
          },
          {
            path: '/instructionalMatters/teaching-tasks/teaching-tasks-add',
            name: 'teaching-tasks-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/teaching-tasks/add')
          },
        ]
      },
      {
        path: '/instructionalMatters/curriculum',
        name: 'curriculum',
        component: () => import('@/views/education-instructionalMatters/curriculum/index'),
        meta: {
          title: '课表'
        },
        children: [{
            path: '/instructionalMatters/curriculum/curriculum-query',
            name: 'curriculum-query',
            meta: {
              title: '全部课表'
            },
            component: () => import('@/views/education-instructionalMatters/curriculum/curriculum')
          },
          {
            path: '/instructionalMatters/curriculum/curriculum-add',
            name: 'curriculum-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/curriculum/add')
          },
          {
            path: '/instructionalMatters/curriculum/curriculum-teacher',
            name: 'curriculum-teacher',
            meta: {
              title: '我的课表（教师）'
            }
          },
          {
            path: '/instructionalMatters/lesson-schedule/curriculum-student',
            name: 'curriculum-student',
            meta: {
              title: '我的课表（学生）'
            },
            component: () => import('@/views/education-instructionalMatters/curriculum/curriculum-student')
          },
          {
            path: '/instructionalMatters/curriculum/curriculum-excel',
            component: () => import('@/views/education-instructionalMatters/curriculum/excelToCurriculum'),
            name: 'curriculum-excel',
            meta: {
              title: '导入课表'
            }
          }
        ]
      },
      {
        path: '/instructionalMatters/curriculum-result',
        name: 'curriculum-result',
        component: () => import('@/views/education-instructionalMatters/curriculum/index'),
        meta: {
          title: '上课结果'
        },
        children: [{
            path: '/instructionalMatters/curriculum-result/curriculum-result-query',
            component: () => import('@/views/education-instructionalMatters/curriculum-result/curriculum-result'),
            name: 'curriculum-result-query',
            meta: {
              title: '上课结果'
            }
          },
          {
            path: '/instructionalMatters/curriculum-result/curriculum-result-add',
            component: () => import('@/views/education-instructionalMatters/curriculum-result/add'),
            name: 'curriculum-result-add',
            meta: {
              title: '添加'
            }
          }
        ]
      },
      {
        path: '/instructionalMatters/curriculum-change',
        name: 'curriculum-change',
        meta: {
          title: '课表变动'
        },
        component: () => import('@/views/education-instructionalMatters/curriculum-change/index'),
        children: [{
            path: '/instructionalMatters/curriculum-change/申请补课',
            component: () => import('@/views/education-instructionalMatters/curriculum-change/index'),
            name: '申请补课',
            meta: {
              title: '申请补课'
            }
          },
          {
            path: '/instructionalMatters/课表/申请停课',
            component: () => import('@/views/education-instructionalMatters/curriculum-change/index'),
            name: '申请停课',
            meta: {
              title: '申请停课'
            }
          },
          {
            path: '/instructionalMatters/课表/申请调课',
            component: () => import('@/views/education-instructionalMatters/curriculum-change/index'),
            name: '申请调课',
            meta: {
              title: '申请调课'
            }
          }
        ]
      },
      {
        path: '/instructionalMatters/classroom',
        component: () => import('@/views/education-instructionalMatters/classroom/index'),
        name: 'classroom',
        meta: {
          title: '课室'
        },
        children: [{
            path: '/instructionalMatters/classroom/classroom-query',
            name: 'classroom-query',
            meta: {
              title: '课室信息'
            },
            component: () => import('@/views/education-instructionalMatters/classroom/Classroom')
          },
          {
            path: '/instructionalMatters/classroom/classroom-add',
            name: 'classroom-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/classroom/add')
          },
        ]
      },
      {
        path: '/instructionalMatters/office',
        component: () => import('@/views/education-instructionalMatters/office/index'),
        name: 'office',
        meta: {
          title: '办公室'
        },
        children: [{
          path: '/instructionalMatters/office/office-query',
          name: 'office-query',
          meta: {
            title: '办公室信息'
          },
          component: () => import('@/views/education-instructionalMatters/office/office')
        },
          {
            path: '/instructionalMatters/office/office-add',
            name: 'office-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/office/add')
          },
        ]
      },
      {
        path: '/instructionalMatters/school-calendar',
        name: 'school-calendar',
        meta: {
          title: '校历'
        },
        component: () => import('@/views/education-instructionalMatters/school-calendar/index'),
        children: [{
            path: '/instructionalMatters/school-calendar/school-calendar-query',
            name: 'school-calendar-query',
            meta: {
              title: '校历'
            },
            component: () => import('@/views/education-instructionalMatters/school-calendar/schoolCalendar')
          },
          // {
          //   path: '/instructionalMatters/school-calendar-query/school-calendar-details',
          //   name: 'school-calendar-details',
          //   meta: {
          //     title: '校历'
          //   },
          //   component: () => import('@/views/education-instructionalMatters/school-calendar/details')
          // },
          {
            path: '/instructionalMatters/school-calendar-query/school-calendar-add',
            name: 'school-calendar-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/school-calendar/add')
          },
          {
            path: '/instructionalMatters/school-calendar-add/school-calendar-update',
            name: 'school-calendar-update',
            meta: {
              title: '调休'
            }
          }
        ]
      },
      {
        path: '/instructionalMatters/teaching-group',
        name: 'teaching-group',
        meta: {
          title: '课程组'
        },
        component: () => import('@/views/education-instructionalMatters/teaching-group/index'),
        children: [{
            path: '/instructionalMatters/teaching-group/teaching-group-query',
            name: 'teaching-group-query',
            meta: {
              title: '课程组'
            },
            component: () => import('@/views/education-instructionalMatters/teaching-group/teaching-group')
          },
          {
            path: '/instructionalMatters/teaching-group-add',
            name: 'teaching-group-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-instructionalMatters/teaching-group/add')
          }
        ]
      },
      {
        path: '/instructionalMatters/semester',
        name: 'semester',
        meta: {
          title: '学期'
        },
        component: () => import('@/views/education-instructionalMatters/semester/index'),
        children: [{
            path: '/instructionalMatters/semester/semester-query',
            name: 'semester-query',
            meta: {
              title: '学期信息'
            },
            // component: () => import('@/views/education-instructionalMatters/semester/semester')
          },
          {
            path: '/instructionalMatters/semester/semester-add',
            name: 'semester-add',
            meta: {
              title: '添加'
            },
            // component: () => import('@/views/education-instructionalMatters/semester/add')
          }
        ]
      },
      {
        path: '/instructionalMatters/time-table',
        name: 'time-table',
        meta: {
          title: '作息'
        },
        component: () => import('@/views/education-instructionalMatters/time-table/index'),
        children: [{
            path: '/instructionalMatters/time-table/time-table-query',
            name: 'time-table-query',
            meta: {
              title: '作息信息'
            }
          },
          {
            path: '/instructionalMatters/time-table/time-table-update',
            name: 'time-table-update',
            meta: {
              title: '修改'
            }
          }
        ]
      },
      {
        path: '/instructionalMatters/personal-schedule',
        component: () => import('@/views/education-instructionalMatters/personal-schedule/index'),
        name: 'personal-schedule',
        meta: {
          title: '个人日程表'
        },
        children: [{
          path: '/instructionalMatters/personal-schedule/personal-schedule-query',
          name: 'personal-schedule-query',
          meta: {
            title: '个人日程表'
          },
          component: () => import('@/views/education-instructionalMatters/personal-schedule/personal-schedule')
        }
        ]
      },
    ]
  },
  // 场地
  {
    path: '/collegeField',
    component: Layout,
    alwaysShow: true,
    name: 'collegeField',
    meta: {
      title: '场地',
      icon: 'chart'
    },
    children: [{
        path: '/collegeField/school',
        name: 'school',
        meta: {
          title: '校区'
        },
        component: () => import('@/views/education-collegeField/school/index'),
        children: [{
            path: '/collegeField/school/school-query',
            name: 'school-query',
            meta: {
              title: '校区信息'
            },
            component: () => import('@/views/education-collegeField/school/school')
          },
          {
            path: '/collegeField/school/school-add',
            name: 'school-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-collegeField/school/add')
          },

        ]
      },
      {
        path: '/collegeField/area',
        name: 'field-apply.vue',
        meta: {
          title: '功能区'
        },
        component: () => import('@/views/education-collegeField/area/index'),
        children: [{
            path: '/collegeField/area/area-query',
            name: 'area-query',
            meta: {
              title: '功能区信息'
            },
            component: () => import('@/views/education-collegeField/area/area')
          },
          {
            path: '/collegeField/area/area-add',
            name: 'area-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-collegeField/area/add')
          },

        ]
      },
      {
        path: '/collegeField/field-type',
        name: 'field-type',
        meta: {
          title: '场地类型'
        },
        component: () => import('@/views/education-collegeField/field-type/index'),
        children: [{
            path: '/collegeField/field-type/fieldType-query',
            name: 'fieldType-query',
            meta: {
              title: '场地类型信息'
            },
            component: () => import('@/views/education-collegeField/field-type/field-type')
          },
          {
            path: '/collegeField/field-type/fieldType-add',
            name: 'fieldType-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-collegeField/field-type/add')
          },

        ]
      },
      {
        path: '/collegeField/field',
        name: 'field',
        meta: {
          title: '场地'
        },
        component: () => import('@/views/education-collegeField/field/index'),
        children: [{
            path: '/collegeField/field/field-query',
            name: 'field-query',
            meta: {
              title: '场地信息'
            },
            component: () => import('@/views/education-collegeField/field/field')
          },
          {
            path: '/collegeField/field/field-add',
            name: 'field-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-collegeField/field/add')
          },
        ]
      },
      {
        path: '/collegeField/field-apply',
        name: 'field-apply',
        meta: {
          title: '场地申请'
        },
        component: () => import('@/views/education-collegeField/field-apply/index'),
        children: [{
            path: '/collegeField/field-apply/field-apply-query',
            name: 'field-apply-query',
            meta: {
              title: '场地申请信息'
            },
            component: () => import('@/views/education-collegeField/field-apply/field-apply')
          },
          {
            path: '/collegeField/field-apply/field-apply-add',
            name: 'field-apply-add',
            meta: {
              title: '场地申请'
            },
            component: () => import('@/views/education-collegeField/field-apply/add')
          },
        ]
      },
      {
        path: '/collegeField/field-department',
        name: 'field-department',
        meta: {
          title: '管理部门'
        },
        component: () => import('@/views/education-collegeField/field-department/index'),
        children: [{
          path: '/collegeField/field-department/field-department-query',
          name: 'field-department-query',
          meta: {
            title: '管理部门信息'
          },
          component: () => import('@/views/education-collegeField/field-department/field-department')
        },
          {
            path: '/collegeField/field-department/field-department-add',
            name: 'field-department-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-collegeField/field-department/add')
          },
        ]
      },
      {
        path: '/collegeField/field-incharge',
        name: 'field-incharge',
        meta: {
          title: '负责人'
        },
        component: () => import('@/views/education-collegeField/field-incharge/index'),
        children: [{
          path: '/collegeField/field-incharge/field-incharge-query',
          name: 'field-incharge-query',
          meta: {
            title: '负责人信息'
          },
          component: () => import('@/views/education-collegeField/field-incharge/field-incharge')
        },
          {
            path: '/collegeField/field-incharge/field-incharge-add',
            name: 'field-incharge-add',
            meta: {
              title: '添加'
            },
            component: () => import('@/views/education-collegeField/field-incharge/add')
          },
        ]
      }
    ]
  },
  {
    path: '/error',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ErrorPages',
    meta: {
      title: 'Error Pages',
      icon: '404'
    },
    children: [{
        path: '401',
        component: () => import('@/views/error-page/401'),
        name: 'Page401',
        meta: {
          title: '401',
          noCache: true
        }
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404'),
        name: 'Page404',
        meta: {
          title: '404',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/error-log',
    component: Layout,
    children: [{
      path: 'log',
      component: () => import('@/views/error-log/index'),
      name: 'ErrorLog',
      meta: {
        title: 'Error Log',
        icon: 'bug'
      }
    }]
  },

  {
    path: '/excel',
    component: Layout,
    redirect: '/excel/export-excel',
    name: 'Excel',
    meta: {
      title: 'Excel',
      icon: 'excel'
    },
    children: [{
        path: 'export-excel',
        component: () => import('@/views/excel/export-excel'),
        name: 'ExportExcel',
        meta: {
          title: 'Export Excel'
        }
      },
      {
        path: 'export-selected-excel',
        component: () => import('@/views/excel/select-excel'),
        name: 'SelectExcel',
        meta: {
          title: 'Export Selected'
        }
      },
      {
        path: 'export-merge-header',
        component: () => import('@/views/excel/merge-header'),
        name: 'MergeHeader',
        meta: {
          title: 'Merge Header'
        }
      },
      {
        path: 'upload-excel',
        component: () => import('@/views/excel/upload-excel'),
        name: 'UploadExcel',
        meta: {
          title: 'Upload Excel'
        }
      }
    ]
  },

  {
    path: '/zip',
    component: Layout,
    redirect: '/zip/download',
    alwaysShow: true,
    name: 'Zip',
    meta: {
      title: 'Zip',
      icon: 'zip'
    },
    children: [{
      path: 'download',
      component: () => import('@/views/zip/index'),
      name: 'ExportZip',
      meta: {
        title: 'Export Zip'
      }
    }]
  },

  {
    path: '/pdf',
    component: Layout,
    redirect: '/pdf/index',
    children: [{
      path: 'index',
      component: () => import('@/views/pdf/index'),
      name: 'PDF',
      meta: {
        title: 'PDF',
        icon: 'pdf'
      }
    }]
  },
  {
    path: '/pdf/download',
    component: () => import('@/views/pdf/download'),
    hidden: true
  },

  {
    path: '/theme',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/theme/index'),
      name: 'Theme',
      meta: {
        title: 'Theme',
        icon: 'theme'
      }
    }]
  },

  {
    path: '/clipboard',
    component: Layout,
    children: [{
      path: 'index',
      component: () => import('@/views/clipboard/index'),
      name: 'ClipboardDemo',
      meta: {
        title: 'Clipboard',
        icon: 'clipboard'
      }
    }]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [{
      path: 'https://github.com/PanJiaChen/vue-element-admin',
      meta: {
        title: 'External Link',
        icon: 'link'
      }
    }]
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
